﻿Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim csb = New SqlConnectionStringBuilder
        csb.DataSource = ".\SqlExpress"
        csb.InitialCatalog = "LiteDynamic2"
        csb.IntegratedSecurity = True

        Dim con = New SqlConnection
        con.ConnectionString = csb.ConnectionString

        Dim cmd = New SqlCommand
        cmd.Connection = con
        'cmd.CommandText = "insert into Domain (DomainId, Description, CreatedBy, CreatedOn) values(@DomainId, @Description, @CreatedBy, @CreatedOn)"
        cmd.CommandText = "select  * from Domain"
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@DomainId", "Clases")
        cmd.Parameters.AddWithValue("@Description", "Desc Clases")
        cmd.Parameters.AddWithValue("@CreatedBy", "Admin")
        cmd.Parameters.AddWithValue("@CreatedOn", DateTime.UtcNow)
        con.Open()

        'cmd.ExecuteNonQuery()
        Dim reader = cmd.ExecuteReader()
        Dim sb = New StringBuilder
        While (reader.Read())
            Dim domainid = reader.GetString(0)
            Dim description = reader("Description")

            sb.AppendLine(
                String.Format("{0} {1} </br>",
                    domainid, description))
        End While
        reader.Close()

        con.Close()

        Me.TextBox1.Text = sb.ToString()

    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim csb = New SqlConnectionStringBuilder
        csb.DataSource = ".\SqlExpress"
        csb.InitialCatalog = "LiteDynamic2"
        csb.IntegratedSecurity = True

        Dim con As DbConnection = New SqlConnection
        con.ConnectionString = csb.ConnectionString

        Dim cmd = New SqlCommand
        cmd.Connection = con
        'cmd.CommandText = "insert into Domain (DomainId, Description, CreatedBy, CreatedOn) values(@DomainId, @Description, @CreatedBy, @CreatedOn)"
        cmd.CommandText = "select  * from Domain"
        cmd.CommandType = CommandType.Text

        Dim adp = New SqlDataAdapter(cmd)


        Dim ds = New DataSet
        adp.Fill(ds, "Domains")

        Me.gvdomain.DataSource = ds.Tables("Domains")
        Me.gvdomain.DataBind()


    End Sub
End Class
